package top.wbhzx.wangpan.config;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import java.util.HashSet;
import java.util.Set;

@Configuration
public class JedisClusterConfig {
    private static final Logger logger = LoggerFactory.getLogger(JedisClusterConfig.class);
    @Autowired
    private RedisProperties redisProperties;

    public JedisClusterConfig() {
    }

    @Bean(name = {"JedisCluster"})
    public  Jedis getJedisCluster() {
    //public JedisCluster getJedisCluster() {
        // 集群redis
//        String[] serverArray = this.redisProperties.getClusterNodes().split(",");
//        Set<HostAndPort> nodes = new HashSet();
//        String[] var3 = serverArray;
//        int var4 = serverArray.length;
//        for(int var5 = 0; var5 < var4 - 1; ++var5) {
//            String ipPort = var3[var5];
//            String[] ipPortPair = ipPort.split(":");
//            nodes.add(new HostAndPort(ipPortPair[0].trim(), Integer.valueOf(ipPortPair[1].trim())));
//        }
//
//        JedisCluster res = new JedisCluster(nodes, this.redisProperties.getCommandTimeout(), 1000, 1, new GenericObjectPoolConfig());
//        return res;
        String[] ipAndPort = this.redisProperties.getClusterNodes().split(":");
        int ipPort = Integer.parseInt(ipAndPort[1]);
        String ip = ipAndPort[0];
        return new Jedis(ip, ipPort);
    }
}
